<?php
// var_dump( $_POST );
// exit;
if(isset($_COOKIE['user'])){
	 echo "<script>alert('已经登录请勿 , 重复登录'); window.location.href='index.php';</script>";
}else{
if(isset($_POST["usernc"]) && isset($_POST["userpwd"])){
		//echo $_POST["userpwd"];
		//echo $_POST["usernc"];
		$usernc= $_POST['usernc'];
		$userpwd= $_POST['userpwd'];
		$url = "http://www.laoyou1.me/shhomer/output_pc/Selectuser.php?usernc=$usernc&userpwd=$userpwd";
		$username = https2_request( $url );
		if( $username == '001' )
		{
			// echo '密码错误 , 请重新登录';
			echo "<script>alert('密码错误 , 请重新登录'); window.location.href='login.php';</script>";
			// header("LOCATION:http://yandudu.com/login.php");
			exit();
		}
		setcookie('user' , $username);

			// echo "<script> alert(111);location.reload();</script>";

			if ( !empty( $_COOKIE['user'] ) ){
					header("LOCATION:http://yandudu.com/index.php");
			}else{
					header("LOCATION:http://yandudu.com/login.php");
					echo '登录失败 , 请重新登录';
			}
		//echo 123;
		}

}

function https2_request($url,$data = null){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;

}
?>
